package com.nuoniu.sibanyun.mapper.erp.in;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.erp.in.InInventoryCategory;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 存货分类 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2021-06-12
 */
public interface InInventoryCategoryMapper extends BaseMapper<InInventoryCategory> {

    @Select("select * from scb_inventory_class where code=#{code} and company_id=#{companyId}")
    InInventoryCategory getByCode(InInventoryCategory inInventoryCategory);

    @Select("select * from scb_inventory_class where name=#{name} and company_id=#{companyId}")
    InInventoryCategory getByName(InInventoryCategory inInventoryCategory);

    @Select("select * from scb_inventory_class where parent_id = #{parentId}")
    List<InInventoryCategory> getByParentIdList(Long parentId);

    /**
     * 修改上级信息
     * @author 小啊刚
     * @date 2020-09-25
     */
    @Update("update scb_inventory_class set parent_ids=REPLACE(parent_ids, #{parentIds}, #{newParentIds}), tree_names=REPLACE(tree_names, #{treeNames}, #{newTreeNames}) " +
            "where  FIND_IN_SET(#{id}, parent_ids ) or id = #{id}")
    void updateChildrenParentIds(Long id, String parentIds, String treeNames, String newParentIds, String newTreeNames);

    void checkInInventoryUsed(Integer companyId,Long id);
}
